package com.xmall.auth.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xmall.common.model.JwtUser;
import com.xmall.common.model.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class XmallUserDetailsService implements UserDetailsService {

    @Autowired
    private ISysUserService sysUserService;
   /* @Autowired
    private SysUserJpaService sysUserJpaService;*/


    @Override
    public JwtUser loadUserByUsername(String s) throws UsernameNotFoundException {

        SysUser sysUser = sysUserService.getOne(new QueryWrapper<SysUser>().lambda().eq(SysUser::getUserLogin,s));
        if(sysUser==null){
            return null;
        }else{
            return new JwtUser(sysUser);
        }

        /*    User user = mockUser(s);
            return user;*/
    }
   /* private User mockUser(String s) {
        SysUser sysUser = sysUserService.getUserByLoginName(s);

        if(sysUser !=null){
            Collection<GrantedAuthority> authorities = new HashSet<>();
            authorities.add(new SimpleGrantedAuthority(sysUser.getRole()));//用户所拥有的角色信息
            User user = new User(sysUser.getUserName(), sysUser.getPassword(),authorities);
            return user;
        }else{
            return null;
        }
    }*/
}
